<script language="javascript">
	function viewProductByStatus(SID){
		window.location='?mod=admin&SID=' + SID;
	}
</script>
<?
if(isset($_GET['method']))
{
	$method = $_GET['method'];
	if($method=="del"){
		$sListId="";
		if(isset($_POST["chon"]))$sListId=$_POST["chon"];
		$sql="delete from ".$prefix."admin where ID in('".str_replace(",","','",$sListId)."')";
		mysql_query($sql);
		Redirect("Bạn đã xoá thành công","?mod=admin");	
	}else if($method=="act"){
		$IdList=$_GET["id"];
		$act=$_GET["act"];
		if($act==1) $iact=0;else $iact=1;
		$sql="update ".$prefix."admin set Active=$iact where ID=$IdList";
		mysql_query($sql);
		Redirect("","?mod=admin");		
	}else if($method=="delete"){
		$IdList=$_GET["id"];
		$sql="delete from ".$prefix."admin where ID=$IdList";
		mysql_query($sql);
		Redirect("Đã xóa thành công","?mod=admin");		
	}
}

	///////Paging
	$strSQL = "select * from ".$prefix."admin";
	
	if(isset($_GET['SID'])){
		$SID = intval($_GET['SID']);
		if($SID != 3){
			$strSQL .= " WHERE Active = '".$SID."'";
		}
	}else{
		$SID = 3;
	}
	
	$pp=10; 
	$parr=array();
	$parr=paging($strSQL,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$strSQL .= " order by ID DESC";
	$strSQL.=" LIMIT $limitvalue, $pp";
	$rs = mysql_query($strSQL) or die('Not query');
	$i=0;
	$isexits=false;
	$url = getURL();
	if(mysql_num_rows($rs)) $isexits=true;
?>
<div class="newsList-path"></div>
	<div style="margin-bottom:5px; font-size:14px;">
	<?
	$sql = "select count(*) as total from ".$prefix."admin";
	$result = mysql_query($sql) or die("Can't connect database");
	$row = mysql_fetch_array($result);
	?>
	 Có <?=$row['total']?> admin được tìm thấy 	<div align="left" class="newsList-search-up">
	 <br />
	<a href="?mod=admin.add"><img src="images/add.png" border="0" alt="Thêm mới"/></a> <a href="?mod=admin"><img src="images/list.png" border="0" alt="Danh sách"/></a>
	</div>
	 </div>
	<div align="right" class="newsList-search-up">
	<strong>Lọc admin </strong>&nbsp;
	
	  &nbsp;
	  <select name="FilterByStatus" id="SID" onchange="return(viewProductByStatus(this.value));">
	<option value="3" <? if($SID == 3){ ?> selected="selected" <? } ?>>--Trạng thái--</option>
	<option value="1" <? if($SID == 1){ ?> selected="selected" <? } ?>>Đã kích hoạt</option>
	<option value="0" <? if($SID == 0){ ?> selected="selected" <? } ?>>Chưa kích hoạt</option>
	  </select>
	</div>

<form name="frmListSp" method="post" action="?mod=admin&method=del" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
	<input type="hidden" name="chon" />
	<table width="100%" border="1" bordercolor="#B2DAEE" cellpadding="4">
		<tr class="newsList-content-head">
		<td width="5%" class="newsList-content-view"><input type="checkbox" name="chkall" value="0" <? if($isexits) echo "onClick=\"docheck(this.form,0);\""?>></td>
			<td width="29%" class="newsList-content-title">Tên đăng nhập </td>
		    <td width="33%" class="newsList-content-title">Tên Email </td>
		    <td width="11%" class="newsList-content-view"><div align="center">Hiển thị </div></td>
	      <td width="22%" class="newsList-content-view"><div align="center">Tùy chọn </div></td>
		</tr>
				<?
				while($rows = mysql_fetch_array($rs))
				{
					$i++;
					$ID = $rows['ID'];
					$TenDN = $rows['TenDN'];
					$Email = $rows['Email'];
					$Active = $rows['Active'];
				?>				
		<tr onmouseover="this.bgColor='#FEF2CB';" onmouseout="this.bgColor='#FFFFFF';" class="newsList-content-list" <? if($i%2==0) echo "bgcolor='#f2fff2'";?>>
			<td class="newsList-content-title"><input type="checkbox" name="Xoa" value="<?=$ID?>" onClick="docheckone(this.form);"></td>
			<td class="newsList-content-title">
            	<table cellpadding="0" cellspacing="0" width="100%">
                <tr>
					<td><b><?=$TenDN?></b></td>
              </table>
			  </td>
		    <td class="newsList-content-title"><table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                  <td><a class="newsList-link newsList-name" href="javasript:void(0);"> <b>
                    <?=$Email?>
                  </b></a> </td>
                </tr>
		      </table></td>
		    <td class="newsList-content-view"><div align="center"><a href="?mod=admin&method=act&act=<?=$Active;?>&id=<?=$ID?>"><?=ImgActive($Active);?></a></div></td>
	      <td class="newsList-content-view"><div align="center">
		  <a href="?mod=admin.add&amp;method=edit&amp;id=<?=$ID?>" class="menu"><img src="images/edit.gif" border="0" /></a> <a href="?mod=admin&amp;method=delete&amp;id=<?=$ID?>" class="menu" onclick="return confirm('Bạn có chắc chắn muốn xóa không?')"><img src="images/delete_on.gif" border="0" /></a></div></td>
        </tr>
		<? }?>
	<tr>
   <td colspan="12" align="center">
   <input type="button" name="New" value="   Thêm mới   " class="Button" onclick="GoBack('?mod=admin.add')">
   <input type="submit" name="submit" value="   Xoá   " class="Button">
   <input type="reset" value="Làm lại" class="Button">   </td>
   </tr>
</table>
</form>
	<div class="newsList-pagging">
	<div class="raovat-paging-bound">
	<span style="padding:5px;">
	<p align="center" class="font">
			<?php echo page_div( "?mod=admin&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	</span>
	</div>
	</div>
	<div class="newsList-button-back"><a href="javascript: history.back()">[Quay lại]</a></div>